package cn.zhangzhan.web.core.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

@Component
@Slf4j
public class PrintBanner implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        // 1. 输出启动完成字样
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
             PrintStream printStream = new PrintStream(baos);) {
            printStream.println(AnsiOutput.toString(AnsiColor.GREEN, "start finish"));
            System.out.println(baos.toString("UTF-8"));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

